#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define MAX 100
#define SUM 10
typedef enum{
    false,true
}bool;

float operate(float, float, char);

void main()
{
    char strzf[SUM];
    float strsz[SUM];
    char str[MAX];
    
    int zfle,szle,tmple;

    zfle = szle = tmple = 0;

    printf("************计算器*************\n");

    if (fgets(str, MAX, stdin) != NULL)
    {
        int length = strlen(str) - 1;
        if(str[length - 1] != '=')
        {
    
            printf("请用=号结尾\n");
        
        }else{

            for (int i = 0; i < length; i++)
            {
                int start = 0;

                bool flag = false;
                switch (str[i])
                {
                case '+':
                    flag = true;
                    
                    strzf[zfle++] = '+';
                    break;
                case '-':
                    flag = true;
                    
                    strzf[zfle++] = '-';
                    break;
                case '*':
                    flag = true;
                    
                    strzf[zfle++] = '*';
                    break;
                case '/':
                    flag = true;
                    
                    strzf[zfle++] = '/';
                    break;
                case '=':
                    flag = true;
                    
                    break;
                default:
                    break;
                }
                if(flag)
                {
                    char strtmp[MAX];
                    for(int j=0;j <= (i-tmple+1);j++)
                    {
                        strtmp[j] =  str[tmple++];
                    }
                    strsz[szle++] = atof(strtmp);
                    tmple = i + 1;
                }
                flag = false;
            }
        }
    }else{
        printf("请输入要计算的内容！\n");
    }

    float leftValue = strsz[0];
    int count = 0;
    while (count < zfle)
    {
        leftValue = operate(leftValue, strsz[count + 1], strzf[count]);
        count++;
    }
    printf("The result is: %2.2f\n", leftValue);
}

float operate(float num1, float num2, char symbol)
{
    switch (symbol)
    {
    case '+':
        return num1 + num2;
        break;
    case '-':
        return num1 - num2;
        break;
    case '*':
        return num1 * num2;
        break;
    case '/':
        return num1 / num2;
        break;
    default:
        printf("Error,please restart!\n");
        return 0;
        break;
    }
}